package com.ztjy.purchase.biz.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ztjy.bean.CBrand;
import com.ztjy.purchase.biz.CBrandBiz;
import com.ztjy.purchase.dao.CBrandDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CBrandBizImpl implements CBrandBiz {
    @Autowired
    private CBrandDao brandDao;
    @Override
    public PageInfo<CBrand> findAllCBrand(CBrand cBrand, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<CBrand> allBrand = brandDao.findAllBrand(cBrand);
        PageInfo<CBrand> pageInfo=new PageInfo<CBrand>(allBrand);
        return pageInfo;
    }

    @Override
    public List<CBrand> findAllCBrand() {
        CBrand cBrand = new CBrand();
        cBrand.setBrandStatus(1);
        return brandDao.findAllBrand(cBrand);
    }

    @Override
    public CBrand findCBrandByBid(Integer bid) {
        return brandDao.selectByPrimaryKey(bid);
    }

    @Override
    public boolean updateCBrand(CBrand cBrand) {
        boolean b = false;
        try {
            b=brandDao.updateByPrimaryKeySelective(cBrand);
        }catch (Exception e){
            e.printStackTrace();
            b=false;
        }
        return b;
    }

    @Override
    public boolean addCBrand(CBrand cBrand) {
        boolean b = false;
        try {
            b=brandDao.insertSelective(cBrand);
        }catch (Exception e){
            e.printStackTrace();
            b=false;
        }
        return b;
    }
}
